// pages/projectOverview/projectOverview.js
var com = require("../../utils/util.js")
const app = getApp()
Page({
 /**
   * 页面的初始数据
   */
  data: {
    userName:'',
    pageSize:10,
    pageNo:1,
    problemImg:[],
    projectImg:[],
    projectList:[],
    tabTxt: ['项目状态', '项目区域', '项目管理'],//分类
    tab: [true, true, true],
    statusList: [{ 'id': '1', 'title': '未开工' }, { 'id': '2', 'title': '已开工' }, { 'id': '3', 'title': '在建' }, { 'id': '4', 'title': '停建' }, { 'id': '5', 'title': '停工' }],
    status_id: 0,
    status_txt: '',
    region_id: 0,
    region_txt: '',
    management_id: 0,
    management_txt: '',
  },

  // 选项卡
  filterTab: function (e) {
    var data = [true, true, true], index = e.currentTarget.dataset.index;
    data[index] = !this.data.tab[index];
    this.setData({
      tab: data
    })
  },

  //筛选项点击操作
  filter: function (e) {
    var self = this, id = e.currentTarget.dataset.id, txt = e.currentTarget.dataset.txt, tabTxt = this.data.tabTxt;
    switch (e.currentTarget.dataset.index) {
      case '0':
        tabTxt[0] = txt;
        self.setData({
          tab: [true, true, true],
          tabTxt: tabTxt,
          status_id: id,
          status_txt: txt
        });
        break;
      case '1':
        tabTxt[1] = txt;
        self.setData({
          tab: [true, true, true],
          tabTxt: tabTxt,
          region_id: id,
          region_txt: txt
        });
        break;
      case '2':
        tabTxt[2] = txt;
        self.setData({
          tab: [true, true, true],
          tabTxt: tabTxt,
          management_id: id,
          management_txt: txt
        });
        break;
    }
    //数据筛选
    self.getDataList();
  },

  //加载数据
  getDataList: function () {
    //调用数据接口，获取数据
    app.thirdScript.http.post('project/list', {
      projectStatus: this.data.status_txt,
      projectZone: this.data.region_txt,
      projectType: this.data.management_txt,
      pageSize: this.data.pageSize,
      pageNo: this.data.pageNo
    }, 'project', this)
  },
  project: function (res) {
    console.log(this.data.status_txt)
    console.log(this.data.region_txt)
    console.log(this.data.management_txt)
    console.log(res)
    if (res.code == 200) {
      var imageUrl = "http://36.33.216.250:8060/zdxm/file/projectFile/";
      for (var i = 0; i < res.content.list.length; i++) {
        var url = imageUrl + res.content.list[i].progressImg
        res.content.list[i].progressImg = url
        this.data.projectImg.push(res.content.list[i])
      }
      this.setData({
        projectList: this.data.projectImg,
        projectImg:[]
      })
    }
    console.log(this.data.projectList)
    console.log(this.data.projectImg)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
   
    var that = this
    wx.getStorage({
      key: 'userInfo',
      success: function(res) {
        console.log(res.data)
        that.setData({
          userName: res.data.name
        })
      },
    })
    app.thirdScript.http.post('project/list', {
      projectStatus: this.data.status_txt,
      projectZone: this.data.region_txt,
      projectType: this.data.management_txt,
      pageSize: this.data.pageSize,
      pageNo: this.data.pageNo,
      userName: this.data.userName
    }, 'set', this)
  },
  set: function(res) {
    console.log(res)
    if (res.code == 200) {     
        var imageUrl = "http://36.33.216.250:8060/zdxm/file/projectFile/";
        for (var i = 0; i < res.content.list.length; i++) {
          var url = imageUrl + res.content.list[i].progressImg
          res.content.list[i].progressImg = url
          this.data.problemImg.push(res.content.list[i])
        }
        this.setData({
          projectList: this.data.problemImg,
        })   
    }
    console.log(this.data.projectList)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})